<?php

namespace addons\qingdong\library;
use fast\Http;

class YunHu
{
    private $appid = "7be7a6a0ab536d85cd351a2b646a3371";
    private $companey=[];

    private $call_api_url="https://yunyuzhineng.cn:8888/voice/v1/call-rs";
    private $call_back_url="";

    public function __construct($companey="")
    {
        if($companey){
            //根据公司信息获取appid

        }
        $this->call_back_url=request()->domain()."/addons/qingdong/library/YunHu/call_back/appid/".$this->appid;
    }
    public function call($f_phone,$t_phone)
    {
        $header=[
            'app_id:'. $this->appid,
            'timestamp:'. $this->getTime(),
        ];
        $data['caller']=$f_phone;
        $data['callee']=$t_phone;
        $data['callBackUrl']=$this->call_back_url;
//        dump($this->call_api_url);
        $res=httpCurl::postData(json_encode($data),$header,$this->call_api_url);
        dump($res);
    }
    public function call_back()
    {

    }

    private function getTime()
    {
        list($msec, $sec) = explode(' ', microtime());

        // 将秒数和微秒数合并为毫秒时间戳
        $milliseconds = (float)sprintf('%.0f', (floatval($sec) + floatval($msec)) * 1000);
        return $milliseconds;
    }
}